Imports System.Data.OleDb

Public Class CustomerOrderRetailLabelLink
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents lblErr As System.Web.UI.WebControls.Label
    Protected WithEvents txtUsername As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnOK As System.Web.UI.WebControls.Button
    Protected WithEvents btnCancel As System.Web.UI.WebControls.Button
    Protected WithEvents radExistedCustomer As System.Web.UI.WebControls.RadioButton
    Protected WithEvents radNewCustomer As System.Web.UI.WebControls.RadioButton
    Protected WithEvents txtEmail As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents txtProductCode As System.Web.UI.WebControls.TextBox
    Protected WithEvents cboEmail As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtCustomerName As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtNewCustomerName As System.Web.UI.WebControls.TextBox

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        btnCancel.Attributes.Add("onclick", "javascript:window.close();return false;")

    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        SaveData()
    End Sub


    Private Sub SaveData()
        Try
            Dim connStr As String = "Provider=SQLOLEDB;" & System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")
            Dim con As New OleDbConnection(connStr)
            con.Open()
            Dim cmdText As String = String.Format("insert into Customer_RetailLabel (CR_Name,[CR_Email],[CR_Password]) values ('{0}','{1}','{2}')", txtNewCustomerName.Text, txtEmail.Text, txtPassword.Text)
            Dim cmd As New OleDbCommand(cmdText, con)
            cmd.ExecuteNonQuery()
            cmd.CommandText = "SELECT @@IDENTITY"
            Dim cusId As Integer = CType(cmd.ExecuteScalar(), Integer)

            cmdText = String.Format("insert into PO_Customer_Lines (Req_No,Cont_Tag_No,PONo_Supplier,PONo_Number,PONo_Type,CR_Customer_Id) values ({0},{1},{2},{3},'{4}',{5})", Req_No, Cont_Tag_No, PONo_Supplier, PONo_Number, PONo_Type, cusId)
            cmd.CommandText = cmdText
            cmd.ExecuteNonQuery()

            Dim productCode As String
            Dim arrProductCode As String() = txtProductCode.Text.Split(","c)
            For Each productCode In arrProductCode
                cmdText = String.Format("insert into PO_Product_Lines (PO_Order,[PONo_Supplier],[Product_Code]) values ('{0}','{1}','{2}')", PONo_Number, PONo_Supplier, productCode)
                cmd.CommandText = cmdText
                cmd.ExecuteNonQuery()
            Next

            con.Close()
            con = Nothing
            cmd = Nothing
        Catch ex As Exception

        End Try
        Page.RegisterStartupScript("windowClose", "<script language='javascript'>window.close();</script>")

    End Sub

    Property Req_No() As Integer
        Get
            If (viewstate("Req_No") Is Nothing) Then
                If Not (Request("Req_No") Is Nothing) Then
                    viewstate("Req_No") = Request("Req_No")
                Else
                    viewstate("Req_No") = 0
                End If
            End If
            Return Convert.ToInt32(viewstate("Req_No"))
        End Get
        Set(ByVal Value As Integer)
            viewstate("Req_No") = Value
        End Set
    End Property

    Property Cont_Tag_No() As Integer
        Get
            If (viewstate("Cont_Tag_No") Is Nothing) Then
                If Not (Request("Cont_Tag_No") Is Nothing) Then
                    viewstate("Cont_Tag_No") = Request("Cont_Tag_No")
                Else
                    viewstate("Cont_Tag_No") = 0
                End If
            End If
            Return Convert.ToInt32(viewstate("Cont_Tag_No"))
        End Get
        Set(ByVal Value As Integer)
            viewstate("Cont_Tag_No") = Value
        End Set
    End Property

    Property PONo_Supplier() As Integer
        Get
            If (viewstate("PONo_Supplier") Is Nothing) Then
                If Not (Request("PONo_Supplier") Is Nothing) Then
                    viewstate("PONo_Supplier") = Request("PONo_Supplier")
                Else
                    viewstate("PONo_Supplier") = 0
                End If
            End If
            Return Convert.ToInt32(viewstate("PONo_Supplier"))
        End Get
        Set(ByVal Value As Integer)
            viewstate("PONo_Supplier") = Value
        End Set
    End Property

    Property PONo_Number() As Integer
        Get
            If (viewstate("PONo_Number") Is Nothing) Then
                If Not (Request("PONo_Number") Is Nothing) Then
                    viewstate("PONo_Number") = Request("PONo_Number")
                Else
                    viewstate("PONo_Number") = 0
                End If
            End If
            Return Convert.ToInt32(viewstate("PONo_Number"))
        End Get
        Set(ByVal Value As Integer)
            viewstate("PONo_Number") = Value
        End Set
    End Property

    Property PONo_Type() As String
        Get
            If (viewstate("PONo_Type") Is Nothing) Then
                If Not (Request("PONo_Type") Is Nothing) Then
                    viewstate("PONo_Type") = Request("PONo_Type")
                Else
                    viewstate("PONo_Type") = 0
                End If
            End If
            Return Convert.ToString(viewstate("PONo_Type"))
        End Get
        Set(ByVal Value As String)
            viewstate("PONo_Type") = Value
        End Set
    End Property

End Class
